package org.se.scut.hibernate.dao.service;

import java.util.Collections;
import java.util.List;

import org.se.scut.hibernate.dao.CommentDAO;
import org.se.scut.hibernate.dao.DAOFactory;
import org.se.scut.hibernate.dao.model.Comment;
import org.se.scut.hibernate.dao.model.UserInfo;
import org.se.scut.hibernate.dao.service.iface.ICommentService;

public class CommentService implements ICommentService {

	private CommentDAO commentDAO = DAOFactory.getCommentDAO();
	

	@Override
	public List<Comment> getCommentsByUserID(int userID, int from, int count) {
		if (from >= 0 && count > 0) {
			return commentDAO.getCommentsByUserID(userID, from, count);
		}
		return Collections.emptyList();
	}

	@Override
	public boolean delete(int deleteID, int userID) {
		Comment comment = commentDAO.find(Comment.class, deleteID);
		if(comment.getCreator().getId() == userID)
		return commentDAO.delete(comment);
		return false;
	}

	@Override
	public int create(Comment model, int creatorID, int ablumID, int pictureID) {
		return commentDAO.create(model, creatorID, pictureID);
	}

	

}
